let fs=require('fs');
//同步方式写入文件
let startTime=new Date().getTime();
for(let i=1;i<=1000;i++){
    fs.writeFileSync("./sync.txt","node好难学！",{flag:"a"})
}
let endTime=new Date().getTime();
console.log("同步耗时："+(endTime-startTime));

//异步方式写入文件
let asyncStartTime=new Date().getTime();
let finishNum=0;
for(let j=0;j<1000;j++){
    fs.writeFile("./aysnc.txt","node好难学！",{flag:"a"},function(err){
        if(err==null){
            finishNum++;
            if(finishNum==1000){
                let asyncEndTime=new Date().getTime();
                console.log("异步耗时："+(asyncEndTime-asyncStartTime));
            }
        }
    })
}